package com.lb.jwitter.action;

import java.io.File;
import java.util.ArrayList; 
import java.util.Collection; 
import java.util.Date; 
import java.util.GregorianCalendar;
import java.util.Locale;

import com.lb.jwitter.service.ConditionReport; 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import com.lb.jwitter.util.Message; 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import java.util.List; 
import java.util.Map; 
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

import java.io.*;

import jxl.format.Alignment;
import jxl.format.VerticalAlignment;
import jxl.write.*;
import java.util.*;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.write.DateFormat;
import jxl.write.Number;

import com.lb.jwitter.util.ApplicationContextProvider; 
import com.opensymphony.xwork2.ActionContext; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQLDTTXADMDiemDat;
import com.lb.jwitter.service.TblQLDTTXADMDiemDatService;
import com.lb.jwitter.service.TblQLDTTXADMKetQuaXetTuyen;
import com.lb.jwitter.service.TblQLDTTXADMKetQuaXetTuyenService;
import com.lb.jwitter.service.TblQLDTTXADMKhoa;
import com.lb.jwitter.service.TblQLDTTXADMKhoaService;
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemTong;
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemTongService;
import com.lb.jwitter.service.TblQLDTTXAThongBaoTuyenSinh;
import com.lb.jwitter.service.TblQLDTTXAThongBaoTuyenSinhService;
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemXetTuyen;
import com.lb.jwitter.service.TblQLDTTXAHoSoDiemXetTuyenService;
import com.lb.jwitter.service.ViewHoSoXetTuyenDiem;
import com.lb.jwitter.service.ViewHoSoXetTuyenDiemService;
import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyen;
import com.lb.jwitter.service.TblQLDTTXAHoSoXetTuyenService;
import com.lb.jwitter.service.TblQLDTTXADMThangDiem;
import com.lb.jwitter.service.TblQLDTTXADMThangDiemService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class XetTuyenAction{

    private Message msg; 
    public Message getMsg() { return msg; }



    private TblQLDTTXAHoSoDiemXetTuyen tblQLDTTXAHoSoDiemXetTuyen; 
    public TblQLDTTXAHoSoDiemXetTuyen getTblQLDTTXAHoSoDiemXetTuyen () {
        return this.tblQLDTTXAHoSoDiemXetTuyen ;
 }

    private Collection<TblQLDTTXAHoSoDiemXetTuyen> tblQLDTTXAHoSoDiemXetTuyens; 
    public Collection<TblQLDTTXAHoSoDiemXetTuyen> getTblQLDTTXAHoSoDiemXetTuyens() {
        return this.tblQLDTTXAHoSoDiemXetTuyens; 
      } 

    private TblQLDTTXAHoSoDiemXetTuyenService tblQLDTTXAHoSoDiemXetTuyenService; 

    private Collection<TblQLDTTXAHoSoXetTuyen> tblQLDTTXAHoSoXetTuyens; 
    public Collection<TblQLDTTXAHoSoXetTuyen> getTblQLDTTXAHoSoXetTuyens() {
         return this.tblQLDTTXAHoSoXetTuyens; 
    }

    private TblQLDTTXAHoSoXetTuyenService tblQLDTTXAHoSoXetTuyenService; 

    private Collection<TblQLDTTXADMThangDiem> tblQLDTTXADMThangDiems; 
    public Collection<TblQLDTTXADMThangDiem> getTblQLDTTXADMThangDiems() {
         return this.tblQLDTTXADMThangDiems; 
    }

    private TblQLDTTXADMThangDiemService tblQLDTTXADMThangDiemService; 

	
	  private TblTaiKhoan taiKhoanDangNhap; 
	 public TblTaiKhoan getTaiKhoanDangNhap() { 
	     return taiKhoanDangNhap; 
	 } 
	 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
	     this.taiKhoanDangNhap = taiKhoanDangNhap; 
	 } 
	 private TblQuyenChiTietService tblQuyenChiTietService;
		 @Autowired // Injected by Spring 
	     ApplicationContextProvider contextProvider; 
	
	 private Collection<ViewHoSoXetTuyenDiem> viewHoSoXetTuyenDiems;
	 private ViewHoSoXetTuyenDiemService viewHoSoXetTuyenDiemService;
	 
	 private List<TblQLDTTXAThongBaoTuyenSinh> tblQLDTTXAThongBaoTuyenSinhs;
	 private TblQLDTTXAThongBaoTuyenSinhService tblQLDTTXAThongBaoTuyenSinhService;	
	 
	 private Collection<TblQLDTTXADMKetQuaXetTuyen> tblQLDTTXADMKetQuaXetTuyens;
	 private TblQLDTTXADMKetQuaXetTuyenService tblQLDTTXADMKetQuaXetTuyenService;
	 
	 private Collection<TblQLDTTXAHoSoDiemTong> tblQLDTTXAHoSoDiemTongs;
	 private TblQLDTTXAHoSoDiemTongService tblQLDTTXAHoSoDiemTongService;
	
	
	 private String hoTen;
	 private Long thongBaoId;
	 
	 private int trangThaiId;
	 
	 private TblQLDTTXAThongBaoTuyenSinh tblQLDTTXAThongBaoTuyenSinh;
	 private TblQLDTTXADMKhoaService tblQLDTTXADMKhoaService;
	 private TblQLDTTXADMKhoa tblQLDTTXADMKhoa;
	 private Double diemDat;
	 private Long khoaId;
	 
	 private List<TblQLDTTXADMKhoa> tblQLDTTXADMKhoas;
  public String form() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
     
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient");
    
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSo_DiemXetTuyen", "xem")){ 
        return "noprivilege"; 
    } 
    
    //////////////////get Service
    tblQLDTTXAThongBaoTuyenSinhService = (TblQLDTTXAThongBaoTuyenSinhService) context.getBean("tbl_QLDTTXA_ThongBaoTuyenSinhClient");
 
    tblQLDTTXADMKhoaService = (TblQLDTTXADMKhoaService) context.getBean("tbl_QLDTTXA_DM_KhoaClient");
	  
    tblQLDTTXADMThangDiemService = (TblQLDTTXADMThangDiemService) context.getBean("tbl_QLDTTXA_DM_ThangDiemClient");
	  
	tblQLDTTXAHoSoXetTuyenService = (TblQLDTTXAHoSoXetTuyenService) context.getBean("tbl_QLDTTXA_HoSoXetTuyenClient");
	   
	tblQLDTTXAHoSoDiemXetTuyenService = (TblQLDTTXAHoSoDiemXetTuyenService) context.getBean("tbl_QLDTTXA_HoSo_DiemXetTuyenClient");
	
	tblQLDTTXADMKetQuaXetTuyenService =(TblQLDTTXADMKetQuaXetTuyenService) context.getBean("tbl_QLDTTXA_DM_KetQuaXetTuyenClient");
	
	tblQLDTTXAHoSoDiemTongService = (TblQLDTTXAHoSoDiemTongService) context.getBean("tbl_QLDTTXA_HoSo_DiemTongClient");

	TblQLDTTXADMDiemDatService tblQLDTTXADMDiemDatService = (TblQLDTTXADMDiemDatService) context.getBean("tbl_QLDTTXA_DM_DiemDatClient");
;
	//////////////////
    tblQLDTTXADMThangDiems = tblQLDTTXADMThangDiemService.findAlltblQLDTTXADMThangDiem(0, 0);
    
    tblQLDTTXADMKetQuaXetTuyens = tblQLDTTXADMKetQuaXetTuyenService.findAlltblQLDTTXADMKetQuaXetTuyen(0, 0);
    
    //thong bao Tuyen Sinh
      List<ConditionReport> cons = new ArrayList<ConditionReport>(); 

      if(thongBaoId != null && thongBaoId != 0){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("id");
		    con.setValue1(thongBaoId);
		    con.setOperator("eq");
		    cons.add(con);
	  } else {
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("thoiGianBatDau");
		    con.setValue1("");
		    con.setOperator("max");
		    cons.add(con);
	  }
      tblQLDTTXAThongBaoTuyenSinhs = tblQLDTTXAThongBaoTuyenSinhService.findtblQLDTTXAThongBaoTuyenSinhByCondition(cons, 0, 0);
      
      tblQLDTTXAThongBaoTuyenSinh = new TblQLDTTXAThongBaoTuyenSinh();
      for(TblQLDTTXAThongBaoTuyenSinh tbl : tblQLDTTXAThongBaoTuyenSinhs){
    	  tblQLDTTXAThongBaoTuyenSinh = tbl;
      }
      
      tblQLDTTXAThongBaoTuyenSinhs = tblQLDTTXAThongBaoTuyenSinhService.findAlltblQLDTTXAThongBaoTuyenSinh(20, 1);

      //dm khoa
	  if(khoaId != null && khoaId != 0){
		  tblQLDTTXADMKhoa = tblQLDTTXADMKhoaService.gettblQLDTTXADMKhoa(khoaId);
			 
	  } else {
		    tblQLDTTXADMKhoa = tblQLDTTXADMKhoaService.gettblQLDTTXADMKhoa(new Long(1));
	  }
	  
	  tblQLDTTXADMKhoas = tblQLDTTXADMKhoaService.findAlltblQLDTTXADMKhoa( 0, 0);

      ////////////get HoSo XetTuyen
      cons.clear();
	  if(hoTen != null && !hoTen.equalsIgnoreCase("")){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("hoTen");
		    con.setValue1("%" + hoTen + "%");
		    con.setOperator("like");
		    cons.add(con);
	  }
	  if(trangThaiId >= 0){
		   if(trangThaiId != 0){
			   if(trangThaiId == 2){
					  
					  ConditionReport con = new ConditionReport(); 
					    con.setCol("trangThaiId");
					    con.setValue1(20);
					    con.setValue2(21);
					    con.setOperator("between");
					    cons.add(con);
				  }
				  else {
					    ConditionReport con = new ConditionReport(); 
					    con.setCol("trangThaiId");
					    con.setValue1(trangThaiId);
					    con.setOperator("eq");
					    cons.add(con);
				  }
		  } else {
			    ConditionReport con = new ConditionReport(); 
			    con.setCol("trangThaiId");
			    con.setValue1(1);
			    con.setOperator("eq");
			    cons.add(con);
		  }
	  }
	  
	  if(thongBaoId != null && thongBaoId != 0){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("thongBaoId.id");
		    con.setValue1(thongBaoId);
		    con.setOperator("eq");
		    cons.add(con);
	  } else if(tblQLDTTXAThongBaoTuyenSinh.getId() != null && !tblQLDTTXAThongBaoTuyenSinh.getId().equals(new Long(0))){
		  	ConditionReport con = new ConditionReport(); 
		    con.setCol("thongBaoId.id");
		    con.setValue1(tblQLDTTXAThongBaoTuyenSinh.getId());
		    con.setOperator("eq");
		    cons.add(con);
	  }
	  if(khoaId != null && khoaId != 0){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("khoaId.id");
		    con.setValue1(khoaId);
		    con.setOperator("eq");
		    cons.add(con);
	  } else {
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("khoaId.id");
		    con.setValue1(new Long(1));
		    con.setOperator("eq");
		    cons.add(con);
	  }
	  
	  if(true){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("maHoSo");
		    con.setValue1("asc");
		    con.setOperator("order");
		    cons.add(con);
	  }
	  
	  tblQLDTTXAHoSoXetTuyens = tblQLDTTXAHoSoXetTuyenService.findtblQLDTTXAHoSoXetTuyenByCondition(cons, 0, 0); 

	  ////////get Diem Xet Tuyen va Diem Tong
      cons.clear();
	  if(hoTen != null && !hoTen.equalsIgnoreCase("")){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("hoSoId.hoTen");
		    con.setValue1("%" + hoTen + "%");
		    con.setOperator("like");
		    cons.add(con);
	  }
	  
	  if(thongBaoId != null && thongBaoId != 0){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("hoSoId.thongBaoId.id");
		    con.setValue1(thongBaoId);
		    con.setOperator("eq");
		    cons.add(con);
	  } else if(tblQLDTTXAThongBaoTuyenSinh.getId() != null && !tblQLDTTXAThongBaoTuyenSinh.getId().equals(new Long(0))){
		  	ConditionReport con = new ConditionReport(); 
		    con.setCol("hoSoId.thongBaoId.id");
		    con.setValue1(tblQLDTTXAThongBaoTuyenSinh.getId());
		    con.setOperator("eq");
		    cons.add(con);
	  }
	  
	  if(khoaId != null && khoaId != 0){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("hoSoId.khoaId.id");
		    con.setValue1(khoaId);
		    con.setOperator("eq");
		    cons.add(con);
	  } else {
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("hoSoId.khoaId.id");
		    con.setValue1(new Long(1));
		    con.setOperator("eq");
		    cons.add(con);
	  }
	  
	  if(trangThaiId >= 0){
		   if(trangThaiId != 0){
			   if(trangThaiId == 2){
					  
					  ConditionReport con = new ConditionReport(); 
					    con.setCol("hoSoId.trangThaiId");
					    con.setValue1(20);
					    con.setValue2(21);
					    con.setOperator("between");
					    cons.add(con);
				  }
				  else {
					    ConditionReport con = new ConditionReport(); 
					    con.setCol("hoSoId.trangThaiId");
					    con.setValue1(trangThaiId);
					    con.setOperator("eq");
					    cons.add(con);
				  }
		  } else {
			    ConditionReport con = new ConditionReport(); 
			    con.setCol("hoSoId.trangThaiId");
			    con.setValue1(1);
			    con.setOperator("eq");
			    cons.add(con);
		  }
	  }
	  
	  tblQLDTTXAHoSoDiemXetTuyens = tblQLDTTXAHoSoDiemXetTuyenService.findtblQLDTTXAHoSoDiemXetTuyenByCondition(cons, 0, 0);

	  tblQLDTTXAHoSoDiemTongs = tblQLDTTXAHoSoDiemTongService.findtblQLDTTXAHoSoDiemTongByCondition(cons, 0, 0);

	  cons.clear();
	  if(thongBaoId != null && thongBaoId != 0){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("thongBaoId.id");
		    con.setValue1(thongBaoId);
		    con.setOperator("eq");
		    cons.add(con);
	  } else if(tblQLDTTXAThongBaoTuyenSinh.getId() != null && !tblQLDTTXAThongBaoTuyenSinh.getId().equals(new Long(0))){
		  	ConditionReport con = new ConditionReport(); 
		    con.setCol("thongBaoId.id");
		    con.setValue1(tblQLDTTXAThongBaoTuyenSinh.getId());
		    con.setOperator("eq");
		    cons.add(con);
	  }
	  if(khoaId != null && khoaId != 0){
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("khoaId.id");
		    con.setValue1(khoaId);
		    con.setOperator("eq");
		    cons.add(con);
	  } else {
		    ConditionReport con = new ConditionReport(); 
		    con.setCol("khoaId.id");
		    con.setValue1(new Long(1));
		    con.setOperator("eq");
		    cons.add(con);
	  }
	  if(true){
		  ConditionReport con = new ConditionReport(); 
		    con.setCol("suDung");
		    con.setValue1(true);
		    con.setOperator("eq");
		    cons.add(con);
	  }
	  List<TblQLDTTXADMDiemDat> dMDiemDats  = tblQLDTTXADMDiemDatService.findtblQLDTTXADMDiemDatByCondition(cons , 1, 1);
	  for(TblQLDTTXADMDiemDat tbl : dMDiemDats) {
		  diemDat = tbl.getDiemDat();
	  }
	  
	  return Action.SUCCESS; 
	  
      } 
      catch(Exception e){ 
      System.out.println("Loi Form tbl_QLDTTXA_HoSo_DiemXetTuyen Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 
  private String saveStr;
  public String save() throws Exception 
  { 
   try{ 	
       Map session = ActionContext.getContext().getSession();
       taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
       if( taiKhoanDangNhap == null) return "noprivilege";
       
      ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
      
      tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient");
      
      if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSo_DiemXetTuyen", "them")
         || !tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSo_DiemXetTuyen", "xoa")
         || !tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSo_DiemTong", "them")
         || !tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_HoSo_DiemTong", "xoa")
    	  
      ){ 
          return "noprivilege"; 
      } 
      
    tblQLDTTXAThongBaoTuyenSinhService = (TblQLDTTXAThongBaoTuyenSinhService) context.getBean("tbl_QLDTTXA_ThongBaoTuyenSinhClient");
   
    tblQLDTTXADMThangDiemService = (TblQLDTTXADMThangDiemService) context.getBean("tbl_QLDTTXA_DM_ThangDiemClient");
  	  
  	tblQLDTTXAHoSoXetTuyenService = (TblQLDTTXAHoSoXetTuyenService) context.getBean("tbl_QLDTTXA_HoSoXetTuyenClient");
  	   
  	tblQLDTTXAHoSoDiemXetTuyenService = (TblQLDTTXAHoSoDiemXetTuyenService) context.getBean("tbl_QLDTTXA_HoSo_DiemXetTuyenClient");
  	
  	tblQLDTTXADMKetQuaXetTuyenService =(TblQLDTTXADMKetQuaXetTuyenService) context.getBean("tbl_QLDTTXA_DM_KetQuaXetTuyenClient");
  	
  	tblQLDTTXAHoSoDiemTongService = (TblQLDTTXAHoSoDiemTongService) context.getBean("tbl_QLDTTXA_HoSo_DiemTongClient");

  	
  	JSONArray jsonArr = (JSONArray) JSONSerializer.toJSON( saveStr );
	for(int i = 0; i < jsonArr.size() ; i++){
		JSONObject obj = jsonArr.getJSONObject(i);
	    List<ConditionReport> cons = new ArrayList<ConditionReport>();
		
	    int hoSoId = obj.getInt( "hoSoId" );
	    
	    if(true){
		    ConditionReport con = new ConditionReport(); 
			con.setCol("hoSoId.id");
			con.setValue1(new Long(hoSoId));
			con.setOperator("eq");
			cons.add(con);
	    }
	    //Xoa tat ca cac hang hoso_Diem cu trong DB
	    tblQLDTTXAHoSoDiemXetTuyens = tblQLDTTXAHoSoDiemXetTuyenService.findtblQLDTTXAHoSoDiemXetTuyenByCondition(cons, 0, 0);
	    
	    List<String> hoSoIdList = new ArrayList<String>();
	    for(TblQLDTTXAHoSoDiemXetTuyen hoSoDiemXetTuyen : tblQLDTTXAHoSoDiemXetTuyens)
	    	hoSoIdList.add(hoSoDiemXetTuyen.getId().toString());	
	    if(hoSoIdList.size() > 0)
	    	tblQLDTTXAHoSoDiemXetTuyenService.deleteListtblQLDTTXAHoSoDiemXetTuyen(hoSoIdList);
	    
	  //Xoa tat ca cac hang hoso_DiemTong trong DB
	    tblQLDTTXAHoSoDiemTongs = tblQLDTTXAHoSoDiemTongService.findtblQLDTTXAHoSoDiemTongByCondition(cons, 0, 0);
	    
	    hoSoIdList.clear();
	    for(TblQLDTTXAHoSoDiemTong hoSoDiemTong : tblQLDTTXAHoSoDiemTongs)
	    	hoSoIdList.add(hoSoDiemTong.getId().toString());	
	    if(hoSoIdList.size() > 0)
	    	tblQLDTTXAHoSoDiemTongService.deleteListtblQLDTTXAHoSoDiemTong(hoSoIdList);
	    
	    //HoSoXetTuyen
	    TblQLDTTXAHoSoXetTuyen tblQLDTTXAHoSoXetTuyen = tblQLDTTXAHoSoXetTuyenService.gettblQLDTTXAHoSoXetTuyen(new Long(hoSoId));

	    tblQLDTTXAHoSoXetTuyenService.updatetblQLDTTXAHoSoXetTuyen(tblQLDTTXAHoSoXetTuyen);
	    
	    JSONArray thangDiemList = obj.getJSONArray("thangDiemList");  	 

	    for(int j = 0; j < thangDiemList.size() ; j++){
	    	JSONObject thangDiemObj = thangDiemList.getJSONObject(j);
	    	
	    	//thangDiem
	    	int thangDiemId = thangDiemObj.getInt("thangDiemId");
	    	TblQLDTTXADMThangDiem tblQLDTTXADMThangDiem = new TblQLDTTXADMThangDiem();
	    	tblQLDTTXADMThangDiem.setId(new Long(thangDiemId));
	    	
	    	//hoSo_DiemXetTuuyen
	    	TblQLDTTXAHoSoDiemXetTuyen tblQLDTTXAHoSoDiemXetTuyen = new TblQLDTTXAHoSoDiemXetTuyen();
	    	tblQLDTTXAHoSoDiemXetTuyen.setHoSoId(tblQLDTTXAHoSoXetTuyen);
	    	tblQLDTTXAHoSoDiemXetTuyen.setThangDiemId(tblQLDTTXADMThangDiem);
	    	
	    	tblQLDTTXAHoSoDiemXetTuyenService.createtblQLDTTXAHoSoDiemXetTuyen(tblQLDTTXAHoSoDiemXetTuyen);
	    }
	    
	    Double diemTong = obj.getDouble("diemTong");
	    
	    TblQLDTTXAHoSoDiemTong tblQLDTTXAHoSoDiemTong = new TblQLDTTXAHoSoDiemTong();
	    //set HosoId
	    tblQLDTTXAHoSoDiemTong.setHoSoId(tblQLDTTXAHoSoXetTuyen);
	    //Set canBoId
	    tblQLDTTXAHoSoDiemTong.setCanBoId(taiKhoanDangNhap.getCanBoId());
	    //set diemTong
	    tblQLDTTXAHoSoDiemTong.setDiemTong(diemTong);
	    //set ngay xet tuyen	    

	    GregorianCalendar c = new GregorianCalendar(); 
	    c.setTime(new Date());
	    XMLGregorianCalendar d = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); 
	    tblQLDTTXAHoSoDiemTong.setNgayXetTuyen(d);
	    
	    //set ket qua
	    String ketQua = obj.getString("ketQua");
	    cons.clear();
	    if(true){
		    ConditionReport con = new ConditionReport(); 
			con.setCol("ma");
			con.setValue1(ketQua);
			con.setOperator("eq");
			cons.add(con);
	    }
		tblQLDTTXADMKetQuaXetTuyens = tblQLDTTXADMKetQuaXetTuyenService.findtblQLDTTXADMKetQuaXetTuyenByCondition(cons, 1, 1);
		for(TblQLDTTXADMKetQuaXetTuyen tblQLDTTXADMKetQuaXetTuyen : tblQLDTTXADMKetQuaXetTuyens)
			tblQLDTTXAHoSoDiemTong.setKetQuaId(tblQLDTTXADMKetQuaXetTuyen);
		
		tblQLDTTXAHoSoDiemTongService.createtblQLDTTXAHoSoDiemTong(tblQLDTTXAHoSoDiemTong);
		
	    //set trang thai la da xet tuyen
	    if(ketQua.equalsIgnoreCase("KD")){
	    	tblQLDTTXAHoSoXetTuyen.setTrangThaiId(20);
	    } else {
	    	tblQLDTTXAHoSoXetTuyen.setTrangThaiId(21);
	    }
	    
	    tblQLDTTXAHoSoXetTuyenService.updatetblQLDTTXAHoSoXetTuyen(tblQLDTTXAHoSoXetTuyen);
	}
	
	
  	  return Action.SUCCESS; 
  	  
        } 
        catch(Exception e){ 
        System.out.println("Loi Save tbl_QLDTTXA_HoSo_DiemXetTuyen Action"); 
       e.printStackTrace(); 
      return Action.ERROR; 
   } 
   } 

public Collection<ViewHoSoXetTuyenDiem> getViewHoSoXetTuyenDiems() {
	return viewHoSoXetTuyenDiems;
}
public void setViewHoSoXetTuyenDiems(
		Collection<ViewHoSoXetTuyenDiem> viewHoSoXetTuyenDiems) {
	this.viewHoSoXetTuyenDiems = viewHoSoXetTuyenDiems;
}
public List<TblQLDTTXAThongBaoTuyenSinh> getTblQLDTTXAThongBaoTuyenSinhs() {
	return tblQLDTTXAThongBaoTuyenSinhs;
}
public void setTblQLDTTXAThongBaoTuyenSinhs(
		List<TblQLDTTXAThongBaoTuyenSinh> tblQLDTTXAThongBaoTuyenSinhs) {
	this.tblQLDTTXAThongBaoTuyenSinhs = tblQLDTTXAThongBaoTuyenSinhs;
}
public Long getThongBaoId() {
	return thongBaoId;
}
public void setThongBaoId(Long thongBaoId) {
	this.thongBaoId = thongBaoId;
}

public String getHoTen() {
	return hoTen;
}
public void setHoTen(String hoTen) {
	this.hoTen = hoTen;
}
public void setTblQLDTTXAHoSoDiemXetTuyens(
		Collection<TblQLDTTXAHoSoDiemXetTuyen> tblQLDTTXAHoSoDiemXetTuyens) {
	this.tblQLDTTXAHoSoDiemXetTuyens = tblQLDTTXAHoSoDiemXetTuyens;
}
public Collection<TblQLDTTXADMKetQuaXetTuyen> getTblQLDTTXADMKetQuaXetTuyens() {
	return tblQLDTTXADMKetQuaXetTuyens;
}
public void setTblQLDTTXADMKetQuaXetTuyens(
		Collection<TblQLDTTXADMKetQuaXetTuyen> tblQLDTTXADMKetQuaXetTuyens) {
	this.tblQLDTTXADMKetQuaXetTuyens = tblQLDTTXADMKetQuaXetTuyens;
}
public Collection<TblQLDTTXAHoSoDiemTong> getTblQLDTTXAHoSoDiemTongs() {
	return tblQLDTTXAHoSoDiemTongs;
}
public void setTblQLDTTXAHoSoDiemTongs(
		Collection<TblQLDTTXAHoSoDiemTong> tblQLDTTXAHoSoDiemTongs) {
	this.tblQLDTTXAHoSoDiemTongs = tblQLDTTXAHoSoDiemTongs;
}
public TblQLDTTXAThongBaoTuyenSinh getTblQLDTTXAThongBaoTuyenSinh() {
	return tblQLDTTXAThongBaoTuyenSinh;
}
public void setTblQLDTTXAThongBaoTuyenSinh(
		TblQLDTTXAThongBaoTuyenSinh tblQLDTTXAThongBaoTuyenSinh) {
	this.tblQLDTTXAThongBaoTuyenSinh = tblQLDTTXAThongBaoTuyenSinh;
}
public void setSaveStr(String saveStr) {
	this.saveStr = saveStr;
}
public Double getDiemDat() {
	return diemDat;
}
public void setDiemDat(Double diemDat) {
	this.diemDat = diemDat;
}
public Long getKhoaId() {
	return khoaId;
}
public void setKhoaId(Long khoaId) {
	this.khoaId = khoaId;
}
public List<TblQLDTTXADMKhoa> getTblQLDTTXADMKhoas() {
	return tblQLDTTXADMKhoas;
}
public void setTblQLDTTXADMKhoas(List<TblQLDTTXADMKhoa> tblQLDTTXADMKhoas) {
	this.tblQLDTTXADMKhoas = tblQLDTTXADMKhoas;
}
public TblQLDTTXADMKhoa getTblQLDTTXADMKhoa() {
	return tblQLDTTXADMKhoa;
}
public void setTblQLDTTXADMKhoa(TblQLDTTXADMKhoa tblQLDTTXADMKhoa) {
	this.tblQLDTTXADMKhoa = tblQLDTTXADMKhoa;
}
public int getTrangThaiId() {
	return trangThaiId;
}
public void setTrangThaiId(int trangThaiId) {
	this.trangThaiId = trangThaiId;
}

 } 
 
